rm(list = setdiff(ls(), lsf.str()))



#Germany-------------------------
load("Study 1/Altered Data/Study1_Germany.RData")

summary(germany<-glm(vote_intention_populist~zero1(agre)+zero1(open)+zero1(con)+zero1(ext)+zero1(neu)+female+age + income+income_missing + education + zero1(lr_ideology)+lr_ideology_missing, data=data, family=binomial,  weights = z000011a))
germany_vote<-data.frame(exp(cbind(coef(germany), confint(germany)))) 
germany_vote<-germany_vote[2,]                
colnames(germany_vote )[1]="Estimate"
colnames(germany_vote )[2]="Lo"
colnames(germany_vote )[3]="Up"
germany_vote$sample<-"GESIS 2017"
germany_vote$Country<-"Germany"

#NL 2012 --------------------
load("Study 1/Altered Data/Study1_NL_12.RData")
m2<-glm(populist ~ zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age + as.factor(education) +income + income_missing + lr_placement11, data=data, family="binomial")
NL_12<-data.frame(exp(cbind(coef(m2), confint(m2)))) 
NL_12<-NL_12[2,]                
colnames(NL_12 )[1]="Estimate"
colnames(NL_12 )[2]="Lo"
colnames(NL_12 )[3]="Up"
NL_12$sample<-"Election 2012"
NL_12$Country<-"Netherlands"

#NL 2017 --------------------
load("Study 1/Altered Data/Study1_NL_17.RData")
m1<-glm(populist ~ zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) + female + age+ as.factor(education) + income + income_missing  + lr_placement + lr_placement_missing, data=data, family="binomial")
NL_17<-data.frame(exp(cbind(coef(m1), confint(m1)))) 
NL_17<-NL_17[2,]                
colnames(NL_17 )[1]="Estimate"
colnames(NL_17 )[2]="Lo"
colnames(NL_17 )[3]="Up"
NL_17$sample<-"Election 2017"
NL_17$Country<-"Netherlands"

#UK - British Election Studies -----------------------
load("Study 1/Altered Data/Study1_UK_BES.RData")
vote.UKIPw6 <- glm(w6_voteUKIP ~zero1(agre) + zero1(open) + zero1(con) + zero1(ext) + zero1(neu) +female +Age+ Age_missing + Ed_GSCE_DG + Ed_GSCE_AC + Ed_A_level + Ed_Undergraduate + Ed_Postgrad + income + income_missing + zero1(w6_pol_cynicism) + zero1(w4_immiatt) + zero1(w6_redistribution), data=data_BES, family="binomial")
UK_bes<-data.frame(exp(cbind(coef(vote.UKIPw6), confint(vote.UKIPw6)))) 
UK_bes_agre<-UK_bes[2,]                
colnames(UK_bes_agre )[1]="Estimate"
colnames(UK_bes_agre )[2]="Lo"
colnames(UK_bes_agre )[3]="Up"
UK_bes_agre$sample<-"UK Election 2015"
UK_bes_agre$Country<-"United \n Kingdom"

#Create plot -------------
comb_vote<-rbind(UK_bes_agre, germany_vote, NL_12, NL_17)
comb_vote$sample <-factor(comb_vote$sample, levels=c('UK Election 2015', 'GESIS 2017', 'Election 2017', 'Election 2012'))
comb_vote$Country <-factor(comb_vote$Country, levels=c('United \n Kingdom', 'Germany', 'Netherlands'))

#Plot figure------------
fig2 <- ggplot(comb_vote ,aes(x=sample, y=Estimate, group=Country))+geom_pointrange(aes(ymin=Lo,ymax=Up), size=1)  + theme_bw()+theme(legend.position="off")+ylab("Odds ratio of voting for a populist party/politician")+xlab("")+geom_hline(yintercept=1,linetype = "dashed", color="red") + coord_flip() + facet_grid(Country~., scales = "free_y")+ theme(axis.text.x=element_text(size=14), strip.text.y=element_text(size=14)) + geom_rect(data = subset(comb_vote,Country == 'Meta \n analysis'),aes(fill = Country),xmin = -Inf,xmax = Inf, ymin = -Inf,ymax = Inf, alpha = 0.3) +  theme(strip.text.y = element_text(angle = 360))

ggsave(fig2, file="Figures/fig1_meta_lr_ideology.pdf", dpi=900, width = 7, height =8)


